<template>
  <view class="whole">
    <view class="search">
      <text class="searchtext">市场</text>
      <view class="searchinput">
        <u-search
          placeholder="搜索藏品名"
          shape="square"
          v-model="value"
          :show-action="false"
          bg-color="#292B2B"
          color="#666666"
          border-color="rgba(255,255,255,0.2200)"
        ></u-search>
        <text class="input_text" @click="$u.debounce(search, 1000, true)"
          >搜索</text
        >
      </view>
      <image
        src="/static/calendar.png"
        class="calendar"
        @click="toonline_list"
      ></image>
    </view>

    <view class="tabs">
      <u-tabs
        :list="list"
        :is-scroll="false"
        :current="current"
        @change="change"
        bg-color="transparent"
        active-color="#1FE7E7"
        inactive-color="#ffffff"
        :bar-style="barStyle"
      ></u-tabs>
      <image :src="price_img" class="price" @click="price_sort"></image>
    </view>

    <view class="CollectionNew_item">
      <block v-for="(item, index) in marketlist" :key="index">
        <view class="Collection_img" @click="todetail(index)">
          <view class="">
            <image :src="item.cover" class="CollectionNew_image"></image>
          </view>
          <view class="Collection_right">
            <text class="Collection_right_text">{{ item.name }}</text>
            <text class="item_center">{{ item.on_sale_num }}件在售</text>
            <text class="Collection_right_text">¥ {{ item.price }}</text>
          </view>
        </view>
      </block>
    </view>

    <empty :show.sync="pagestate"></empty>
  </view>
</template>

<script>
import api from "../../api/api";
import tip from "@/utils/tip.js";
export default {
  data() {
    return {
      value: "",
      GongGestate: true,
      list: [
        {
          name: "综合",
        },
        {
          name: "销量",
        },
        {
          name: "价格",
        },
      ],
      current: 0,
      scrollTop: 0,
      page: 1,
      marketlist: [],
      pagestate: false,
      barStyle: {
        width: 32 + "px",
        height: 3 + "px",
        borderRadius: 2 + "px",
      },
      price_id: 0,
      price_img: "/static/price.png",
    };
  },
  onLoad() {
    // this.lists();
  },
  onShow() {
    // this.page = 1;
    // this.list()

    this.lists();
  },

  onReachBottom() {
    this.page++;
    this.lists();
  },
  onPullDownRefresh() {
    this.page = 1;
    this.current = 0;
    this.price_img = "/static/price.png";

    this.lists();
  },
  onPageScroll(e) {
    this.scrollTop = e.scrollTop;
  },
  methods: {
    toonline_list() {
      if (!uni.getStorageSync("token")) {
        uni.navigateTo({
          url: "../signin/signin",
        });
        return;
      }
      uni.navigateTo({
        url: `../../pages/online_list/online_list?user_product_id=${this.user_product_id}`,
      });
    },
    search() {
      this.page = 1;
      this.pagestate = false;
      this.lists();
    },
    change(index) {
      this.current = index;
      this.price_id = 0;
      this.price_img = "/static/price.png";
      if (index == 1) {
        var sale = 1;
      }
      this.lists("", sale);
    },
    price_sort() {
      this.current = 2;
      var price_sort = 1;
      if (this.price_id == 2) {
        this.price_id = 1;
        this.price_img = "/static/price_low.png";
        price_sort = 2;
      } else {
        this.price_id = 2;
        this.price_img = "/static/price_high.png";
      }
      console.log(price_sort, "this.price_sort");
      this.lists(price_sort, "");
    },
    async lists(price_sort, sale) {
      let res = await api.goodsList({
        method: "POST",
        query: {
          page: this.page,
          limit: this.limit,
          name: this.value,
          price_sort: price_sort,
          sale: sale,
        },
      });
      if (res.code == 0) {
        uni.stopPullDownRefresh();
        if (this.page == 1) {
          this.marketlist = res.data;
          if (res.data.length == 0) {
            this.pagestate = true;
          }
        } else {
          if (res.data.length > 0) {
            this.marketlist = [...this.marketlist, ...res.data];
          }
        }
      }else {
        tip.defaults(res.msg);
      }
    },
    todetail(index) {
      uni.navigateTo({
        url: `../../pages/goods_detail/goods_detail?product_id=${
          this.marketlist[index].product_id
        }&market=${true}&price=${this.marketlist[index].price}`,
      });
    },
  },
};
</script>

<style lang="scss">
/deep/ .u-tab-bar {
  width: 64rpx !important;
  background: #1fe7e7;
  margin-left: -5px !important;
  margin-top: 50rpx !important;
}
.tabs {
  /deep/ .u-tab-item {
    height: 50px !important;
  }
}
</style>

<style lang="scss" scoped>
@import "../../style/yuanchuang.scss";
.whole {
  width: 100%;
  height: 100%;
  background-color: $bg-color1;
  min-height: 100vh;
}
.search {
  display: flex;
  justify-content: space-between;
  align-content: center;
  color: #ffffff;
  margin: 0 30rpx;
  .searchinput {
    flex: 0.9;
    height: 72rpx;
    border-radius: 35rpx;
    position: relative;
    display: flex;
    align-items: center;
    // display: inline-block;
    line-height: 72rpx;
    .input_text {
      position: absolute;
      padding: 0 36rpx;
      right: 0;
      box-sizing: border-box;

      width: 128rpx;
      height: 68rpx;
      background: linear-gradient(90deg, #1fe6e6 0%, #3f9ed2 48%, #df7fd6 100%);
      border-radius: 6rpx;
      text-align: center;
      font-size: 28rpx;
      font-weight: 400;
      color: #ffffff;
      line-height: 68rpx;
    }
  }

  .searchtext {
    font-size: 22px;
    margin: auto 0;
  }
  .calendar {
    width: 26px;
    height: 26px;
    margin: auto 0;
  }
}
.tabs {
  margin: 0 0 30rpx 0;
  height: 50px;
  //   border-bottom: 5rpx solid #101428;
  position: relative;
  .price {
    position: absolute;
    right: 60rpx;
    top: 0rpx;
    width: 16rpx;
    height: 24rpx;
    z-index: 99;
    padding: 30rpx 10rpx 30rpx 100rpx;
  }
}
.totop {
  position: fixed;
  right: 0;
  bottom: 300rpx;
}
.listwhole {
  display: flex;
  margin: 24rpx 30rpx;
  border: 2rpx solid #101428;
  border-radius: 12px;
  background-color: #101428;
  // align-items: center;
  align-items: flex-start;

  justify-content: space-between;
  .list_left {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    margin: 24rpx;
    height: 176rpx;
    .list_left_top {
      font-size: 28rpx;
      color: #0c1125;
      font-weight: 500;
      margin-bottom: 24rpx;
    }
    .list_left_center {
      font-size: 24rpx;
      font-weight: 400;
      color: #bbbbbe;
      margin-bottom: 5rpx;
      overflow: hidden;
      -webkit-line-clamp: 1;
      text-overflow: clip;
      display: -webkit-box;
      -webkit-box-orient: vertical;
    }
    .list_left_bottom {
      font-size: 24rpx;
      font-weight: 400;
      color: #bbbbbe;
    }
  }
  .list_right {
    margin: 24rpx;
    .list_right_img {
      width: 220rpx;
      height: 176rpx;
      border-radius: 24rpx;
    }
  }
}
.CollectionNew_item {
  display: flex;
  justify-content: space-between;
  flex-direction: row;
  align-items: flex-start;
  flex-wrap: wrap;
  color: #ffffff;
  margin: 0 30rpx;
  .Collection_img {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    // background-color: #101428;
    border-radius: 15rpx;
    margin: 15rpx 0 15rpx 0;
    // width: 48%;
    width: 330rpx;
    height: 540rpx;
    position: relative;

    background-image: url("/static/backgroundNew.png");
    background-repeat: no-repeat;
    background-size: 100% 522rpx;
    .CollectionNew_image {
      width: 330rpx;
      height: 330rpx;
      border-radius: 24rpx;
    }
    .Collection_right {
      margin-left: 30rpx;
      //   padding: 20rpx 0;
      display: flex;
      flex-direction: column;
      //   justify-content: space-between;
      align-items: flex-start;
      height: 200rpx;
      .Collection_right_text {
        // margin-top: 20rpx;
        margin-top: 10rpx;
        font-size: 36rpx;
        overflow: hidden;
        -webkit-line-clamp: 1;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        font-weight: bold;
      }
      .item_center {
        margin-top: 12rpx;
        color: #bbbbbe;
        font-size: 28rpx;
      }
      .Collectio_button {
        margin-top: 24rpx;
        width: 280rpx;
        height: 60rpx;
        border-radius: 30rpx;
        background-image: linear-gradient(137deg, #39a2ff 0%, #9e00d3 100%);
        text-align: center;
        line-height: 60rpx;
        color: #0c1125;
        font-size: 28rpx;
      }
      .Collectio_openbutton {
        margin-top: 24rpx;
        width: 100%;
        height: 60rpx;
        border-radius: 30rpx;
        background-color: #606060;
        text-align: center;
        line-height: 60rpx;
        color: #0c1125;
        font-size: 28rpx;
      }
    }
  }
}
</style>
